#include <bits/stdc++.h>
using namespace std;

#define ONLINE_JUDGE

#ifndef ONLINE_JUDGE
#define dbg(x...)                             \
	{                                         \
		cerr << "\033[32;1m" << #x << " -> "; \
		err(x);                               \
	}
void err()
{
	cerr << "\033[39;0m" << endl;
}
template <typename T, typename... A>
void err(T a, A... x)
{
	cerr << a << ' ';
	err(x...);
}
#else
#define dbg(...)
#endif

typedef long long LL;

const int N = 2e3 + 50;

bitset<N> G[N];
char g[N][N];
int d[N][N];

bool rvis[N];
int n;
void dfs(int u, vector<int> &l)
{
	rvis[u] = 1;
	l.push_back(u);
	for (int v = G[u]._Find_first(); v <= n; v = G[u]._Find_next(v))
	{
		// if (u == 2) dbg(u, v, G[u][v]);
		if (!rvis[v])
			dfs(v, l);
	}
}

void bfs(int s, int n, int d[])
{
	static bitset<N> vis;
	vis.set();

	static int q[N], st, ed;
	st = ed = 0;
	q[ed++] = s;
	d[s] = 0;
	// dbg(s, d[s]);
	vis[s] = vis[0] = false;
	while (st < ed)
	{
		int u = q[st++];
		// dbg(u, G[u], vis);
		bitset<N> l = G[u] & vis;

		for (int v = l._Find_first(); v <= n; v = l._Find_next(v))
		{
			d[v] = d[u] + 1;
			vis[v] = false;
			q[ed++] = v;
		}
	}
}

vector<int> ans[N];

int main(int argc, char const *argv[])
{
	int k;
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; ++i)
	{
		scanf("%s", g[i] + 1);
		for (int j = 1; j <= n; ++j)
			G[i][j] = (g[i][j] == '1');
	}


	int leng = 0;
	int now = 0;
	for (int i = 1; i <= n; ++i)
	{
		// dbg(i, rvis[11]);

		if (rvis[i])
			continue;
		// dbg(i);

		vector<int> l;
		dfs(i, l);

		for (int st : l)
		{
			// dbg(i, st);
			bfs(st, n, d[st]);
		}

		pair<int, int> dia(l[0], l[0]);

		int nn = l.size();
		// dbg(nn);
		for (int j = 0; j < nn; ++j)
			for (int k = j + 1; k < nn; ++k)
			{
				int u = l[j], v = l[k];
				if (d[u][v] > d[dia.first][dia.second])
				{
					dia = make_pair(u, v);
				}
			}
		leng += d[dia.first][dia.second] + 1;

		int s = dia.first;
		for (int j = 0; j < nn; ++j)
		{
			int v = l[j];
			// dbg(s, v, now + d[s][v]);
			ans[now + d[s][v]].push_back(v);
		}
		now += d[dia.first][dia.second] + 1;
	}
	dbg(now, k);
	if (now < k)
	{
		puts("Nope");
	}
	else
	{
		puts("Yep");
		int r = n;

		for (int i = 0; i < k - 1; ++i)
		{
			r -= ans[i].size();
			printf("%d", (int)ans[i].size());
			sort(ans[i].begin(), ans[i].end());
			for (int x : ans[i])
				printf(" %d", x);
			putchar('\n');
		}
		printf("%d", r);
		for (int i = k - 1; i < leng; ++i)
		{
			sort(ans[i].begin(), ans[i].end());
			for (int x : ans[i])
				printf(" %d", x);
		}
		putchar('\n');
	}

	return 0;
}